<template>
  <div>
    <el-form ref="form" :model="integralGrade" label-width="120px">
      <el-form-item  label="借款额度">
        <el-input-number
          v-model="integralGrade.borrowAmount"
          :min="0"   
          @change="inputChange"  
        ></el-input-number>
      </el-form-item>

      <el-form-item label="积分区间开始">
        <el-input-number
          v-model="integralGrade.integralStart"
          @change="inputChange"
          :min="0"
          
        ></el-input-number>
      </el-form-item>
      <el-form-item label="积分区间结束">
        <el-input-number
          v-model="integralGrade.integralEnd"
          @change="inputChange"
          :min="0"
          
        ></el-input-number>
      </el-form-item>
    </el-form>
    <el-button style="margin-left:120px" :disabled="buttonFlag" @click="saveOrUpdate" type="primary">保存</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      integralGrade: {
        borrowAmount: 1000,
        integralEnd: 0,
        integralStart: 0,
        
      },
      buttonFlag:true
    }
  },
  methods:{
    inputChange(){
      this.buttonFlag = false
    },
    async saveOrUpdate(){
      this.buttonFlag = true
      if(this.$route.params.id){
        const result = await this.$API.integralGrade.updateById(this.integralGrade);
        if(result.code==200){
          this.$message.success(result.message)
          this.$router.push('/core/integral-grade/list')
        }
      }else{
        const result =  await this.$API.integralGrade.saveCoreIntegrade(this.integralGrade)
        if(result.code==200){
          this.$message.success(result.message)
          this.$router.push('/core/integral-grade/list')
        }
      }
      
      
    },
    async getById(id){
      const result = await this.$API.integralGrade.getById(id)
      this.integralGrade = result.data.record
    }
  },
  mounted(){
    if(this.$route.params.id){
      this.getById(this.$route.params.id)
    }else{
       Object.assign(this._data,this.$options.data())
    }
  }
}
</script>

<style></style>
